using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SurveyHost.Core;

namespace SurveyHost.Web
{
    public partial class SurveyHost : MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void LoggedIn(object sender, EventArgs e)
        {
            if (sender == null) throw new ArgumentNullException("sender");
            Login loginControl = (Login)LoginView1.FindControl("loginControl");
            LogHelper.General("User {1} id {0} has logged in.", WebUtil.GetUserId(loginControl.UserName), loginControl.UserName);
        }

        protected void LoginError(object sender, EventArgs e)
        {
            Login loginControl = (Login)LoginView1.FindControl("loginControl");
            LogHelper.General("User login failed; Given user name \"{0}\", request IP: {1}", loginControl.UserName, Page.Request.UserHostAddress);
        }

        protected void LoggedOut(object sender, EventArgs e)
        {
            LogHelper.General("User {1} id {0} has logged out.", WebUtil.CurrentUserId(), HttpContext.Current.User.Identity.Name);
            HttpContext.Current.Session.Abandon();
            Response.Redirect("~/default.aspx", true);
        }
    }
}